//类的组合,构造函数调用顺序
#include <iostream>
#include<cmath>
using namespace std;
class Point //点
{
public:
    Point(float x, float y) : m_x(x), m_y(y)
    {
        print();
        cout << " point con\n";
    }
    Point(const Point& other) 
    {
        *this=other;
        print();
        cout << " point cpycon\n";
    }
    float distances(const Point& other)const
    {
        float dstn;
        dstn=(m_x-other.m_x)*(m_x-other.m_x)+(m_y-other.m_y)*(m_y-other.m_y);
        return sqrt(dstn);
    }
    void print() const
    {
        cout<<"("<<m_x<<" , "<<m_y<<")";
    }
    ~Point()
    {
        print();
        cout<<" point des\n";
    }
private:
    float m_x, m_y;
};

class Segment //线段
{
public:
    Segment(Point A, Point B) : m_pointA(A), m_pointB(B)
    {
        print();
        cout << "Segment con1\n";
    }
    Segment(float x1, float y1, float x2, float y2) : m_pointA(x1, y1), m_pointB(x2, y2)
    {
        print();
        cout << "Segment con2\n";
    }
    void print() const
    {
        m_pointA.print();
        cout<<" ---> ";
        m_pointB.print();
    }
    ~Segment()
    {
        print();
        cout<< "segment des\n";
    }
    float length()const
    {
        return m_pointA.distances(m_pointB);
    }
private:
    Point m_pointA,  m_pointB;
};

int main()
{
    Segment seg1(Point(4,6), Point(3,5));
    Segment seg2(-1, -2, -10, -20);
    cout<<"seg1 len="<<seg1.length()<<endl;
    cout<<"seg2 len="<<seg2.length()<<endl;
    return 0;
}
